package com.huawei.appmarket.oobe.activity;

import android.app.ActionBar;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils.TruncateAt;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.Layout;
import com.huawei.appmarket.R;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailTextListBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailTextListBean.TextListItem;
import com.huawei.appmarket.service.appdetail.view.card.DetailClickCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailPermissionCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailScreenCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailTextListCard;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeBundle;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.Iterator;
import java.util.List;
import o.ayy;
import o.azb;
import o.cfv;
import o.dlf;
import o.dli;
import o.dlt;
import o.Logger;
import o.drl;
import o.drr;
import o.drr.b;
import o.eib;
import o.epv;
import o.ll;

public class OOBEAppDetailActivity extends Activity {
    private BroadcastReceiver ʽ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ OOBEAppDetailActivity ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                if (!"com.huawei.appmarket.oobe.ACTION_GETAPPDETAIL_RESULT".equals(intent.getAction())) {
                    return;
                }
                if (intent.getIntExtra("resultCode", 1) == 0) {
                    this.ˋ.ˊ();
                    this.ˋ.ˎ((DetailResponse) intent.getSerializableExtra("response"));
                    return;
                }
                this.ˋ.ˋ();
            }
        }
    };
    private dlf ˊ;
    private String ˋ;
    private drr ˎ;
    private Button ˏ = null;
    private LinearLayout ॱ = null;
    private boolean ॱॱ;
    private int ᐝ;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ayy.ˋ().ˎ(getWindow());
        ॱ(getResources().getString(R.string.title_activity_app_detail));
        SafeIntent safeIntent = new SafeIntent(getIntent());
        this.ˋ = safeIntent.getStringExtra("detailId");
        this.ᐝ = safeIntent.getIntExtra("index", 0);
        this.ॱॱ = safeIntent.getBooleanExtra("checked", false);
        eib.ॱ(this);
        setContentView(R.layout.hiapp_activity_oobeapp_detail);
        this.ॱ = (LinearLayout) findViewById(R.id.oobe_app_detail_cards);
        ॱ();
        new dlt(this, this.ˋ).ˋ();
        ˏ();
    }

    protected void onResume() {
        super.onResume();
        if (dli.ˏ(this)) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | 4098);
        }
    }

    protected void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("detailId", this.ˋ);
        bundle.putInt("appIndex", this.ᐝ);
        bundle.putBoolean("checked", this.ॱॱ);
    }

    protected void onRestoreInstanceState(Bundle bundle) {
        SafeBundle safeBundle = new SafeBundle(bundle);
        this.ˋ = safeBundle.getString("detailId");
        this.ᐝ = safeBundle.getInt("appIndex");
        this.ॱॱ = safeBundle.getBoolean("checked");
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        finish();
        return true;
    }

    protected void ॱ(String str) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setTitle(str);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    private void ˏ() {
        if (this.ˊ == null) {
            this.ˊ = new dlf();
            this.ˊ.ˏ(findViewById(R.id.oobe_detail_loadingPager));
            this.ˊ.ˊ();
        }
        this.ˊ.ॱ(0);
    }

    private void ˊ() {
        if (this.ˊ != null) {
            this.ˊ.ॱ(8);
            this.ˊ = null;
        }
    }

    private void ˋ() {
        if (this.ˊ != null) {
            this.ˊ.ˋ();
        }
    }

    private void ˎ(DetailResponse detailResponse) {
        if (detailResponse != null) {
            ॱ(detailResponse);
            this.ˎ = new drr();
            drr.ˊ(this.ˎ, new cfv(), detailResponse);
            if (this.ˎ.ॱ() > 0) {
                LayoutInflater from = LayoutInflater.from(this);
                b[] ˏ = this.ˎ.ˏ();
                for (int i = 0; i < ˏ.length; i++) {
                    ˎ(from, this.ॱ, ˏ, i);
                }
            }
            this.ˏ = (Button) findViewById(R.id.oobe_add);
            ˎ();
            this.ˏ.setVisibility(0);
            if (this.ॱॱ) {
                this.ˏ.setEnabled(false);
                this.ˏ.getBackground().setAlpha(76);
                return;
            }
            this.ˏ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ OOBEAppDetailActivity ॱ;

                {
                    this.ॱ = r1;
                }

                public void onClick(View view) {
                    Intent intent = new Intent();
                    intent.putExtra("index", this.ॱ.ᐝ);
                    this.ॱ.setResult(-1, intent);
                    this.ॱ.finish();
                }
            });
        }
    }

    private void ॱ() {
        ll.ˏ(this).ˏ(this.ʽ, new IntentFilter("com.huawei.appmarket.oobe.ACTION_GETAPPDETAIL_RESULT"));
    }

    private boolean ˎ(LayoutInflater layoutInflater, ViewGroup viewGroup, b[] bVarArr, int i) {
        b bVar = bVarArr[i];
        if (!ˎ(bVar)) {
            return false;
        }
        ˊ(bVar);
        View ˊ = bVar.ˊ.ˊ(layoutInflater, viewGroup, null);
        if (ˊ == null || !bVar.ˊ.ˊ(bVar.ʼ())) {
            return false;
        }
        if (bVarArr.length == i + 1) {
            if (bVar.ˊ instanceof DetailTextListCard) {
                ((DetailTextListCard) bVar.ˊ).ᐝ();
            } else if (bVar.ˊ instanceof DetailPermissionCard) {
                ((DetailPermissionCard) bVar.ˊ).ʽ();
            } else {
                Logger.e("OOBE", "detailCard is not instanceof DetailPermissionCard and DetailTextListCard");
            }
        }
        viewGroup.addView(ˊ);
        if (i == bVarArr.length - 1) {
            View view = new View(this);
            view.setLayoutParams(new LayoutParams(-1, epv.ˋ(this, 14)));
            viewGroup.addView(view);
        }
        return true;
    }

    private boolean ˎ(b bVar) {
        if (bVar.ʼ() == null || bVar.ʼ().size() <= 0) {
            return false;
        }
        return true;
    }

    private void ॱ(DetailResponse detailResponse) {
        if (detailResponse != null) {
            List ʻॱ = detailResponse.ʻॱ();
            if (ʻॱ != null && ʻॱ.size() > 0) {
                Iterator it = ʻॱ.iterator();
                while (it.hasNext()) {
                    if (!ˋ((Layout) it.next())) {
                        it.remove();
                    }
                }
            }
        }
    }

    private boolean ˋ(Layout layout) {
        String ˎ = layout.ˎ();
        if (ˎ.equals("detailheadcard") || ˎ.equals("detailscreencard") || ˎ.equals("detailappinfocard") || ˎ.equals("detaileditorrecommendcard") || ˎ.equals("detailclickcard") || ˎ.equals("detailprizecard") || ˎ.equals("detailappintrocard") || ˎ.equals("textlistcard") || ˎ.equals("detailpermissioncard")) {
            return true;
        }
        Logger.ˎ("OOBE", "bad detail card :" + ˎ);
        return false;
    }

    private void ˊ(b bVar) {
        drl o_drl = bVar.ˊ;
        if (o_drl instanceof DetailTextListCard) {
            if (bVar.ʼ() != null) {
                DetailTextListBean detailTextListBean = (DetailTextListBean) bVar.ʼ().get(0);
                if (detailTextListBean.ॱ() != null) {
                    Iterator it = detailTextListBean.ॱ().iterator();
                    while (it.hasNext()) {
                        TextListItem textListItem = (TextListItem) it.next();
                        if (textListItem.ॱ() != 0) {
                            Logger.e("OOBE", "bad DetailTextListCard item, type=" + textListItem.ॱ());
                            it.remove();
                        }
                    }
                }
            }
        } else if (o_drl instanceof DetailClickCard) {
            ((DetailClickCard) o_drl).ˊ(false);
        } else if (o_drl instanceof DetailScreenCard) {
            ((DetailScreenCard) o_drl).ॱ(false);
        } else {
            Logger.e("OOBE", "itemCard is not instanceof DetailTextListCard etc.");
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        if (this.ʽ != null) {
            ll.ˏ(this).ˋ(this.ʽ);
        }
    }

    private void ˎ() {
        if (this.ˏ != null) {
            int ॱ = (int) (((double) azb.ॱ(this)) / 2.0d);
            if (this.ˏ.getWidth() < ॱ) {
                this.ˏ.setWidth(ॱ);
                return;
            }
            ॱ = epv.ˋ(this, 8);
            this.ˏ.setPadding(ॱ, this.ˏ.getPaddingTop(), ॱ, this.ˏ.getPaddingBottom());
            this.ˏ.setMaxWidth(azb.ॱ(this) - epv.ˋ(this, 32));
            this.ˏ.setEllipsize(TruncateAt.END);
        }
    }
}
